package com.zyx.crawlerdemo.jsonparse.orgjson.parse;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * @author Yaxi.Zhang
 * @since 2021/8/12 10:25
 * desc: orgjson解析对象
 */
public class OrgJsonObjectParseTest {
	public static void main(String[] args) {
		// json对象
		String json = "{\"id\":\"07\",\"language\": \"C++\",\"edition\": \"second\",\"author\": \"E.Balagurusamy\"}";
		// JSONObject构造对象
		JSONObject jsonObject = new JSONObject(json);
		// 获取所有的key值
		JSONArray keys = jsonObject.names();
		System.out.println(keys);
		// 获取key对应的value
		String id=jsonObject.getString("id");
		String language=jsonObject.getString("language");
		String edition=jsonObject.getString("edition");
		// 输出结果
		System.out.println(id + "\t" + language + "\t" + edition);
	}
}
